﻿<%@ WebHandler Language="C#" Class="SYS_Product_sel" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
using System.Collections.Generic;
using System.Web.SessionState;

public class SYS_Product_sel : IHttpHandler,IRequiresSessionState {
    sqlhelp sql = new sqlhelp();
    SYS_Productresult result = new SYS_Productresult();
    string str = "";
    DataTable dt = new DataTable();
    List<SYS_Product> SYS_ProductList = new List<SYS_Product>();
	string sort = "createTime";
    string sorttype = "desc";
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }
            if (context.Request["pageNo"] == null) {
                result.code = "0";
                result.msg = "未传递页码";
                unit.send(context, result);
                return;
            }
            string where = " and Enable = 1 ";
            result.code = "1";
            string Id = "";
            if (context.Request["Id"] != null)
            {
                Id = context.Request["Id"].ToString();
                where = where + " and Id = '" + Id + "'";
            }
            string Code = "";
            if(context.Request["Code"] != null ){
                Code = context.Request["Code"].ToString();
                where = where + " and Code = " + Code + "";
            }
            string StoreId = context.Session["comid"].ToString();
            where = where + " and StoreId = '" + StoreId + "'";
            
            string CategoryId = "";
            if(context.Request["CategoryId"] != null ){
                CategoryId = context.Request["CategoryId"].ToString();
                where = where + " and CategoryId = '" + CategoryId + "'";
            } 
            string Title = "";
            if(context.Request["Title"] != null ){
                Title = context.Request["Title"].ToString();
                where = where + " and Title = '" + Title + "'";
            } 
            string SubTitle = "";
            if(context.Request["SubTitle"] != null ){
                SubTitle = context.Request["SubTitle"].ToString();
                where = where + " and SubTitle = '" + SubTitle + "'";
            } 
            string AveragePrice = "";
            if(context.Request["AveragePrice"] != null ){
                AveragePrice = context.Request["AveragePrice"].ToString();
                where = where + " and AveragePrice = '" + AveragePrice + "'";
            } 
            string Price = "";
            if(context.Request["Price"] != null ){
                Price = context.Request["Price"].ToString();
                where = where + " and Price = '" + Price + "'";
            } 
            string ActivityPrice = "";
            if(context.Request["ActivityPrice"] != null ){
                ActivityPrice = context.Request["ActivityPrice"].ToString();
                where = where + " and ActivityPrice = '" + ActivityPrice + "'";
            }
            string DetailText = "";
            if (context.Request["DetailText"] != null)
            {
                DetailText = context.Request["DetailText"].ToString();
                where = where + " and DetailText = '" + DetailText + "'";
            }
            string CreateTime = "";
            if(context.Request["CreateTime"] != null ){
                CreateTime = context.Request["CreateTime"].ToString();
                where = where + " and CreateTime = '" + CreateTime + "'";
            } 
            string Enable = "";
            if(context.Request["Enable"] != null ){
                Enable = context.Request["Enable"].ToString();
                where = where + " and Enable = " + Enable + "";
            }

            int pageIndex = int.Parse(context.Request["pageNo"].ToString());
            dt = sql.GetPermissionsPager(sort, sorttype, pageIndex, 10, where, "SYS_Product").Tables[0];
            result.total = sql.GetCount("SYS_Product",where);
			int len = dt.Rows.Count;
			if (len > 0)
			{
				for (int i = 0; i < len; i++) {
					SYS_Product _SYS_Product = new SYS_Product();
                    _SYS_Product.Id = dt.Rows[i]["Id"].ToString();
                    _SYS_Product.Code = dt.Rows[i]["Code"].ToString();
                    _SYS_Product.StoreId = dt.Rows[i]["StoreId"].ToString();
                    _SYS_Product.CategoryId = dt.Rows[i]["CategoryId"].ToString(); 
                    _SYS_Product.BannerId = dt.Rows[i]["BannerId"].ToString();
                    _SYS_Product.Title = dt.Rows[i]["Title"].ToString(); 
                    _SYS_Product.SubTitle = dt.Rows[i]["SubTitle"].ToString(); 
                    _SYS_Product.AveragePrice = dt.Rows[i]["AveragePrice"].ToString(); 
                    _SYS_Product.Price = dt.Rows[i]["Price"].ToString(); 
                    _SYS_Product.ActivityPrice = dt.Rows[i]["ActivityPrice"].ToString(); 
                    _SYS_Product.Cover = dt.Rows[i]["Cover"].ToString(); 
                    _SYS_Product.DetailText = dt.Rows[i]["DetailText"].ToString(); 
                    _SYS_Product.DetailImgId = dt.Rows[i]["DetailImgId"].ToString(); 
                    _SYS_Product.CreateTime = dt.Rows[i]["CreateTime"].ToString(); 
                    _SYS_Product.Enable = dt.Rows[i]["Enable"].ToString();
                    
					SYS_ProductList.Add(_SYS_Product);
				}
				result.data = SYS_ProductList;
			}

            }
            catch (Exception e1)
            {
                result.code = "0";
                result.msg = e1.Message;
            }
        unit.send(context, result);
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

public class SYS_Productresult : result
{
    public List<SYS_Product> data = new List<SYS_Product>();
    public int total = 0;

}

public class SYS_Product {
    public string Id = "";
    public string Code = "";
    public string StoreId = "";
    public string CategoryId = "";
    public string BannerId = "";
    public string Title = "";
    public string SubTitle = "";
    public string AveragePrice = "";
    public string Price = "";
    public string ActivityPrice = "";
    public string CreateTime = "";
    public string Enable = "";
    public string Cover = "";
    public string DetailText = "";
    public string DetailImgId = "";
}
